package co.com.capsula.pages;

import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.PasswordField;
import org.apache.tapestry5.ioc.annotations.Inject;

import co.com.capsula.beans.Persona;

public class FormDemo {
	
	@Inject
	private Persona persona;
	
	@Persist
	@Property
    private String userName;
	
	@Property
    private String password;
	
	@Property
    private java.util.Date feNacimiento;
	
	@Property
	private int quantity;

    @Component(id = "password")
    private PasswordField passwordField;

    @Component
    private Form form;

    String onSuccess() { 
    	persona.setStrNombre(userName);
    	if (userName.equals("tomas")) {
    		return "FormDemo";
    	} else {
    		form.recordError(passwordField, "Nombre de usuario o password no valido.");
            return null;    		
    	}
    }
    
    String onToClientFromQuantity() { 
      if (quantity == 0) 
    	  return "";

      return null;
    }
    
    Object onParseClientFromQuantity(String input) { 
		if ("".equals(input)) 
			return 0;
		
		return null;
    }
}
